package model

import (
	"gorm.io/gorm"
)

type ControlScore struct {
	gorm.Model
	Type         string `json:"type"`          //1:理科；2：文科；3：综合
	TypeName     string `json:"type_name"`     //理科；文科；综合
	BatchName    string `json:"batch_name"`    //批次名
	Batch        string `json:"batch"`         //批次
	Score        string `json:"score"`         //分数
	MajorScore   string `json:"major_score"`   //专业分数
	Rank         string `json:"rank"`          //
	Year         string `json:"year"`          //年份
	Province     string `json:"province"`      //省份
	ScoreSection string `json:"score_section"` //位次
	Name         string `json:"name"`          //批次名
	Diff         string `json:"diff"`          //未知
}

func FirstControlScore(where ControlScore) (first ControlScore) {
	db.Where(&where, "year", "province", "batch", "batch", "type_name").First(&first)
	return
}

func CreateControlScore(controlScore ControlScore) {
	db.Create(&controlScore)
}

func UpdateControlScore(controlScore ControlScore) {
	db.Where(&controlScore, "year", "province", "batch", "batch", "type_name").Updates(controlScore)
}

func UpdateOrCreateControlScore(controlScore ControlScore) {
	isExist := FirstControlScore(controlScore)
	if isExist.Year == "" {
		CreateControlScore(controlScore)
	} else {
		UpdateControlScore(controlScore)
	}
}
